﻿

//

using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;
using LaserMark.Components.Events;
using LaserMark.Components.Services;
using LaserMark.Components.Utils;
using LaserMark.DataAccess.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LaserMark.Components;
public partial class TipMessage : EventComponentBase
{
    [Inject]
    [NotNull]
    private IGlobalStatus? GlobalStatus { get; set; }

    private CancellationTokenSource? Token { get; set; } = new();

    private List<ConsoleMessageItem> LogItems { get; set; } = new List<ConsoleMessageItem>();

    protected override void OnInitialized()
    {
        base.OnInitialized();
        CommandNames.Add(RibbonTabConstants.LogInfomation);
    }

    protected override void OnRegisterEvent()
    {
        var logEvent = new RibbonTabEvent(RibbonTabConstants.LogInfomation, async item =>
        {
            if (item.Payload is AuditLog log)
            {
                LogItems.Add(new ConsoleMessageItem() { Color = Color.Success, Message = log.Description });
                await InvokeAsync(StateHasChanged);
            }
        });
        Events.Add(logEvent);
        EventBus.RegisterHandler(logEvent);
    }

    private Task OnClear()
    {
        LogItems.Clear();

        return Task.CompletedTask;
    }
}
